class Solution {
public:
    TreeNode* cur = nullptr;
    TreeNode* pre = nullptr;
    TreeNode* Convert(TreeNode* root)
    {
        if (root == nullptr)
            return nullptr;
        Convert(root->left);
        if (cur == nullptr)
        {
            cur = root;
            pre = root;
        }
        else
        {
            pre->right = root;
            root->left = pre;
            pre = root;
        }
        Convert(root->right);
        return cur;
    }
};